package com.泛型;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 泛型 {
	public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
		List<? extends Number> list = Arrays.asList(1,2);
		System.out.println(list.get(0));
		
		/**
		 * JAVA的伪泛型
		 */
		ArrayList<String> list1 = new ArrayList<String>();
		ArrayList<Integer> list2 = new ArrayList<Integer>();
		//打印true
		System.out.println(list1.getClass() == list2.getClass());
		
		/**
		 * 突破泛型约束，通过反射方式依然可以向Integer泛型的list中添加字符串元素
		 */
		list2.getClass().getMethod("add", Object.class).invoke(list2, "abc");
		System.out.println(list2.get(0));
		
		

	}
}

class Test{
	public static <T> T getValue(T x,T y) {
		return x == null? y : x;
	}
	public static void main(String[] args) {
		int test = Test.getValue(2, 3);
		System.out.println(test);
		
		String test1 = Test.<String>getValue(null,"3");
		System.out.println(test1);
	}
}
